package com.digitaleye.dpslite;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.Toast;
import com.downpayment.dps.R;

public class LoginActivity extends Activity {
	
	WebHelper webHelper;
	
	DBHelper dbHelper;
	
	
	@Override
	public void onBackPressed() {

		Intent i = new Intent();

		i.setClass(this, MainActivity.class);

		i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

		startActivity(i);
	}
	
	
	@Override
	public void onConfigurationChanged(Configuration newConfig){
		super.onConfigurationChanged(newConfig);
		setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
	}
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.login_layout);
		
		Utility.adjustBackground(this);
		

		addButtonListeners();
		
		this.webHelper = new WebHelper(this);
		
		this.dbHelper = new DBHelper(this);
		

		
		
	}
	
	public void onAuthenticate(String username, boolean loggedIn){
		if(loggedIn){
			
			/** update username in table **/
			LoginActivity.this.dbHelper.setUsername(username);
			
			//remember username if remember me is checked

			
			//LoginActivity.this.webHelper.getAccountInfo();
			
			/**start next activity, with call back to original  activity (passed through START_TAB) **/
		
			
			
			Bundle extras = LoginActivity.this.getIntent().getExtras();
			String startTab = extras.getString("START_TAB");
			Intent intent = null; 
			
			if(startTab.equals("settings")){
				intent = new Intent(LoginActivity.this, SettingsActivity.class);
			}

			else{
				intent = new Intent(LoginActivity.this, TabRoot.class);
			}
			intent.putExtra("START_TAB", startTab);
			
			intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			
			
			LoginActivity.this.startActivity(intent);
		}
		else{
			Toast.makeText(LoginActivity.this, "Unable to Login. Check that your username and password are correct", Toast.LENGTH_LONG).show();
			
		}
	}
	
	
	public void addButtonListeners(){
		
		
	}

}
